<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'threadlistener.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
</head>

<body>

	<script type="text/javascript" src="style/js/jquery.min.js"></script>
	<script type="text/javascript">
	
	
	function closeBeatThread(name){
		console.log("closeBeatThread ======= "+name);
		$.ajax({
				url:"<%=basePath%>admin/user_closeBeatThread.action",
				datatype:"json",
				data:{threadName:name},
				type:"post",
				async:"true",
			}).success(function(data){
				getThread();
			}).error();
	}
	
	function closeThread(name){
		console.log("close ======= "+name);
		$.ajax({
				url:"<%=basePath%>admin/user_closeThread.action",
				datatype:"json",
				data:{threadName:name},
				type:"post",
				async:"true",
			}).success(function(data){
				getThread();
			}).error();
	}
	
	function reopen(name){
		console.log("reopen ======= "+name);
		$.ajax({
				url:"<%=basePath%>admin/user_reopen.action",
				datatype:"json",
				data:{threadName:name},
				type:"post",
				async:"true",
			}).success(function(data){
				getThread();
			}).error();
	}
	
	function reBeat(name){
		console.log("reopen ======= "+name);
		$.ajax({
				url:"<%=basePath%>admin/user_reBeat.action",
				datatype:"json",
				data:{threadName:name},
				type:"post",
				async:"true",
			}).success(function(data){
				getThread();
			}).error();
	}
	
 	function getThread(){
			$.ajax({
				url:"<%=basePath%>admin/user_getThread.action",
				datatype : "json",
				type : "post",
				async : "true",
			}).success(
					function(data) {
						 console.log(data);
						 var thradNameList = eval(data);
						 $("#thradlist").html("");
						 $("#beatthradlist").html("");
						 $.each(thradNameList[0],function(index,value){
					            $("#thradlist").append(
					            	"<tr>"+
					    				"<td>"+value.threadName+"</td>"+
					    				"<td>"+value.beat+"</td>"+
					    				"<td>"+
					    				"<button onclick=\"reopen('"+value.threadName+"')\">重启</button>"+
					    				"<button onclick=\"closeThread('"+value.threadName+"')\">关闭</button>"+
					    				"</td>"+
					    			"</tr>");
					        });
						 $.each(thradNameList[1],function(index,value){
					            $("#beatthradlist").append(
					            	"<tr>"+
					    				"<td>"+value.threadName+"</td>"+
					    				"<td>"+value.beat+"</td>"+
					    				"<td>"+
					    				"<button onclick=\"reBeat('"+value.threadName+"')\">重启</button>"+
					    				"<button onclick=\"closeBeatThread('"+value.threadName+"')\">关闭</button>"+
					    				"</td>"+
					    			"</tr>");
					        });
					}).error(function(data) {
			});
		}
 		getThread();
		setInterval(getThread, 10000);
		
	</script>
	<span>生命维持线程</span>
	<table width="%80">
		<tr>
			<td width="%20">线程名</td>
			<td width="%20">状态</td>
			<td width="%20">操作</td>
		</tr>

		<tbody id="thradlist">
			
		</tbody>
	</table>
	</br>
	</br>
	<span>心跳线程</span>
	<table width="%80">
		<tr>
			<td width="%20">线程名</td>
			<td width="%20">状态</td>
			<td width="%20">操作</td>
		</tr>

		<tbody id="beatthradlist">
			
		</tbody>
	</table>
</body>
</html>
